<?php
/**
 * Dependency reverse filter
 *
 * PHP version 5
 *
 * @category  W
 * @package   Services
 * @author    Olivier Hoareau <olivier@phppro.fr>
 * @copyright 2009 PHPPRO http://www.phppro.fr
 * @license   http://dev.phppro.fr/license PHPPRO
 * @version   SVN: $Id:$
 * @link      http://dev.phppro.fr/projects/wdependency
 */
require_once 'W/W.php';
require_once 'W/Dependency/Filter/Abstract.php';
/**
 * Dependency reverse filter
 *
 * @category  W
 * @package   Services
 * @author    Olivier Hoareau <olivier@phppro.fr>
 * @copyright 2009 PHPPRO http://www.phppro.fr
 * @license   http://dev.phppro.fr/license PHPPRO
 * @version   SVN: $Id$
 * @link      http://dev.phppro.fr/projects/wdependency
 */
class W_Dependency_Filter_Reverse extends W_Dependency_Filter_Abstract
{
    public function filter($data)
    {
        $data = $data['data'];
        $d = array();
        foreach($data as $node=>$items) {
            foreach($items as $subNode=>$weight){
                if (false === isset($d[$subNode])) {
                    $d[$subNode] = array();
                }
                if (false === isset($d[$subNode][$node])) {
                    $d[$subNode][$node] = 0;
                }
                $d[$subNode][$node]+=$weight;
            }
        }
        return $d;
    }
}